package com.zhang.springcloud.service.impl;

import com.zhang.springcloud.service.StreamOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import java.util.UUID;

@EnableBinding(Source.class)
public class StreamOutputImpl implements StreamOutput {
    @Autowired
    private MessageChannel output;

    @Override
    public String sendOutput() {
        String mess = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(mess).build());
        //output.send(MessageBuilder.withPayload(mess).build());
        System.out.println("消息发送者: "+mess);
        return mess;
    }
}
